package com.yima.baseproj.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
    public static void main(String[] args) {
        String input = "oEdqX64hi0bAbn-l_vyOWcRlNWM8"; // 输入字符串
        String md5 = getMD5(input); // 获取MD5加密字符串
        System.out.println("MD5加密结果（32位小写）: " + md5);
    }

    public static String getMD5(String input) {
        try {
            // 创建MessageDigest实例并指定MD5算法
            MessageDigest md = MessageDigest.getInstance("MD5");
            // 计算输入字符串的MD5值
            byte[] hash = md.digest(input.getBytes());
            // 将字节数组转换为32位小写字符串
            StringBuilder sb = new StringBuilder();
            for (byte b : hash) {
                sb.append(String.format("%02x", b & 0xff));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    public static String splitList(String args) {
        String str = "2cb9f9425668e2f92eb2b6336aacd8e4-张三李四";
        String[] parts = str.split("-");
        if (parts.length > 0) {
            return parts[0];
        }
        return "";
    }
}
